import { createApp } from 'vue'
import './style.css'
import './style/global.css'
import App from './App.vue'
import router from './router'
import { createPinia } from 'pinia'

// Element Plus 全局配置
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
// 全局样式
import '@/styles/index.scss'

import * as echarts from 'echarts'
import * as G6 from '@antv/g6'

// 开发环境启用devtools
const app = createApp(App)  
// 根据环境启用
app.config.devtools = process.env.NODE_ENV === 'development'
const pinia = createPinia()
 // 确保在正确的地方调用
// 注册Element Plus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 注册图标组件
import {
  Odometer,
  DataAnalysis,
  TrendCharts,
  Monitor,
  OfficeBuilding,
  Setting,
  Cloudy,
  Microphone,
  Opportunity
} from '@element-plus/icons-vue'

app.component('Odometer', Odometer)
app.component('DataAnalysis', DataAnalysis)
app.component('TrendCharts', TrendCharts)
app.component('Monitor', Monitor)
app.component('OfficeBuilding', OfficeBuilding)
app.component('Setting', Setting)
app.component('Cloudy', Cloudy)
app.component('Microphone', Microphone)
app.component('Opportunity', Opportunity)

// 全局配置
app.use(pinia)
   .use(router)
   .use(ElementPlus, {
     locale: zhCn,
     size: 'default'
   })

// 全局错误处理
app.config.errorHandler = (err, instance, info) => {
  console.error('全局错误:', { err, instance, info })
}

// 全局属性扩展
app.config.globalProperties.$ELEMENT = { size: 'default' }
app.config.globalProperties.$echarts = echarts
app.config.globalProperties.$G6 = G6.default ? G6.default : G6

// 开发环境启用性能检测
if (import.meta.env.DEV) {
  app.config.performance = true
}

// 在入口文件添加字体
import 'typeface-orbitron'; // 需要先安装typeface-orbitron

app.mount('#app')
